package com.zkzx.truck.controller;

import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * @author young Email:yanghui@zkraising.com
 * @description
 * @company 北京中科智兴物联科技有限公司 @版权所有
 * @since 2021年04月27日 15时12分
 */
public class BaseController {

    private static final String USERID = "userId";

    private final static String HEADER_COMPANY = "companyId";

    @Autowired
    protected HttpServletRequest request;


    /**
     * 获取用户ID
     * @return
     */
    public int getUserId(){
        String userId = request.getHeader(USERID);
        if(Objects.isNull(userId)){
            throw new RuntimeException("获取用户失败");
        }
        return Integer.parseInt(userId);
    }

    /**
     * 获取用户ID
     * @return
     */
    public int getCompanyId(){
        String companyId = request.getHeader(HEADER_COMPANY);
        if(Objects.isNull(companyId)){
            throw new RuntimeException("获取企业失败");
        }
        return Integer.parseInt(companyId);
    }

}
